﻿using BCCommon;
using BCDto.TMS.MarketingCoupon.MarketingCouponStatistics;
using BCService.TMS.MarketingCoupon.MarketingCouponStatistics;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;

namespace BCTMSRESTful.Controllers.Management.TMS.MarketingCoupon
{
    /// <summary>
    /// 优惠券统计
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class MarketingCouponStatisticsController : ManagementBaseController
    {
        private readonly IMarketingCouponStatisticsService marketingCouponStatisticsService;
        public MarketingCouponStatisticsController(IMarketingCouponStatisticsService marketingCouponStatisticsService)
        {
            this.marketingCouponStatisticsService = marketingCouponStatisticsService;
        }


        /// <summary>
        /// 获取优惠券统计
        /// </summary>
        /// <param name="isCommonBusiness">是否通用</param>
        /// <param name="vehicleTransportBusinessConfigId">运输业务id</param>
        /// <returns></returns>
        [HttpGet("[action]/{is_common_business}")]
        [ProducesResponseType(typeof(MarketingCouponStatisticsDto), 200)]
        public IActionResult GetStatistics([FromRoute(Name = "is_common_business")] bool isCommonBusiness,
            [FromQuery(Name = "vehicle_transport_business_config_id")] long? vehicleTransportBusinessConfigId)
        {
            if (Admin.AgentRecord == null)
            {
                throw new ArgumentException(" 用户验证失败,错误操作 ");
            }
            var result = this.marketingCouponStatisticsService.GetMarketingCouponStatistics(this.Admin, isCommonBusiness, vehicleTransportBusinessConfigId);
            return this.Ok(result);
        }
        /// <summary>
        /// 获取优惠券的详情统计
        /// </summary>
        /// <param name="isCommonBusiness">是否通用</param>
        /// <param name="vehicleTransportBusinessConfigId">运输业务id</param>
        /// <param name="isExpired">是否过期</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns></returns>
        [HttpGet("[action]/{is_common_business}")]
        [ProducesResponseType(typeof(IEnumerable<MarketingCouponStatisticsDetailDto>), 200)]
        public IActionResult GetDetailList([FromRoute(Name = "is_common_business")] bool isCommonBusiness,
            [FromQuery(Name = "vehicle_transport_business_config_id")] long? vehicleTransportBusinessConfigId,
            [FromQuery(Name = "is_expired")] bool? isExpired,
            [FromQuery(Name = "start_date")] DateTime? startDate,
            [FromQuery(Name = "end_date")] DateTime? endDate)
        {
            if (Admin.AgentRecord == null)
            {
                throw new ArgumentException(" 用户验证失败,错误操作 ");
            }
            var result = this.marketingCouponStatisticsService.GetDetailList(this.Admin, isCommonBusiness, vehicleTransportBusinessConfigId, isExpired,
                startDate, endDate);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取优惠券的详情统计(分页)
        /// </summary>
        /// <param name="isCommonBusiness">是否通用</param>
        /// <param name="vehicleTransportBusinessConfigId">运输业务id</param>
        /// <param name="isExpired">是否过期</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("[action]/{is_common_business}")]
        [ProducesResponseType(typeof(PageableList<MarketingCouponStatisticsDetailDto>), 200)]
        public IActionResult GetDetailQuery([FromRoute(Name = "is_common_business")] bool isCommonBusiness,
            [FromQuery(Name = "vehicle_transport_business_config_id")] long? vehicleTransportBusinessConfigId,
            [FromQuery(Name = "is_expired")] bool? isExpired,
            [FromQuery(Name = "start_date")] DateTime? startDate,
            [FromQuery(Name = "end_date")] DateTime? endDate,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            if (Admin.AgentRecord == null)
            {
                throw new ArgumentException(" 用户验证失败,错误操作 ");
            }
            var result = this.marketingCouponStatisticsService.GetDetailQuery(this.Admin, isCommonBusiness, vehicleTransportBusinessConfigId, isExpired,
                startDate, endDate, pageIndex, pageSize);
            return this.Ok(result);
        }
    }
}
